<template>
	<!-- 修改集采单 -->
	<div class="page" v-loading="loading">
		<el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>修改集采单</el-breadcrumb-item>
		</el-breadcrumb>
		<el-form class="content" ref="form" :model="form" status-icon :rules="rules" label-width="120px">
			<el-form-item label="金额(分)">
				<el-input size="small" v-model="form.amount" disabled></el-input>
			</el-form-item>
			<el-form-item label="汇率">
				<el-input size="small" v-model="form.exchangeRate" disabled></el-input>
			</el-form-item>
			<el-form-item label="发票编号">
				<el-input size="small" v-model="form.invoiceNumber"></el-input>
			</el-form-item>
			<el-form-item label="收付款凭证号">
				<el-input size="small" v-model="form.paymentNumber"></el-input>
			</el-form-item>
			<el-form-item label="数量">
				<el-input size="small" v-model="form.qty" disabled></el-input>
			</el-form-item>
			<el-form-item label="供应商">
				<span>{{form.supplierName}}</span>
			</el-form-item>
			<el-form-item label="商品列表">
				<el-table :data="form.stockInItems" border style="width: 90%;">
					<el-table-column show-overflow-tooltip prop="goodsName" label="商品名称" width="100">
					</el-table-column>
					<el-table-column label="数量" prop="qty" >
					</el-table-column>
					<el-table-column label="单位" prop="unit">
					</el-table-column>
					<el-table-column width="140px" prop="price" label="单价" >
					</el-table-column>
					<el-table-column prop="tax" label="税率%" >
					</el-table-column>
					<el-table-column label="总额(分)" prop="amount" >
					</el-table-column>
				</el-table>
			</el-form-item>
			<el-form-item label="单据编号" prop="receiptNumber">
				<el-input size="small" v-model="form.receiptNumber"></el-input>
			</el-form-item>
			<!-- <el-form-item label="仓库名称" prop="warehouseName">
				<el-input size="small" v-model="form.warehouseName"></el-input>
			</el-form-item> -->
			<el-form-item label="备注">
				<el-input size="small" v-model="form.remark" disabled></el-input>
			</el-form-item>
			<el-form-item>
				<el-button size="small" type="primary" @click="submitForm('form')">确认修改</el-button>
				<el-button size="small" @click="utils.back">取消</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>
<script>
import axios from 'axios';
import cityThree from '../../common/cityThree.vue';
import selectOneSupplier from '../../common/selectOneSupplier.vue';
import selectMoreGoods from '../../common/selectMoreGoods.vue';
export default {
	name: "add",
	data() {
		return {
			status :1, 
			form: {
				"amount": 1,				//金额
				"exchangeRate": 10,			//汇率
				"invoiceNumber": "11",		//发票编号
				"paymentNumber": "1",		//收付款凭证号
				"qty": 1,					//数量
				"receiptNumber": "1",		//单据编号
				"stockInType": "PRESALELIS",	//类型
				"supplierContact": "11",	//供应商联系人
				"supplierId": 1,			//供应商Id
				"supplierMobile": "32",		//供应商手机
				"supplierName": "3132",		//供应商
				"packQty": 3,				//件数
				"remark": "1",				//备注
				"warehouseName": "1",		//仓库
				"stockInItems": [
					// {
					// 	"amount": 312311,		//金额
					// 	"categoryId": 1,		//分类ID	
					// 	"categoryName": "31",	//分类名称
					// 	"goodsId": 33232,		//商品id
					// 	"goodsName": "1",		//商品名称
					// 	"goodsNo": "1",			//商品编号
					// 	"unit": "13",			//单位
					// 	"tax": 1,				//税率
					// 	"qty": 1,				//数量
					// 	"price": 3,				//无税金额
					// 	"remark": "31",			//备注
					// 	"taxPrice": 1,			//含税金额
					// 	"packType": "3",		//包装方式
					// 	"packQty": 1332			//件数
					// }
				],
			},
			rules: {
				amount: [{ required: true, message: '金额不能为空', trigger: 'blur' }],
				exchangeRate: [{ required: true, message: '汇率不能为空', trigger: 'blur' }],
				qty: [{ required: true, message: '数量不能为空', trigger: 'blur' }],
				receiptNumber: [{ required: true, message: '单据编号不能为空', trigger: 'blur' }],
				stockInType: [{ required: true, message: '类型不能为空', trigger: 'blur' }],
				packQty: [{ required: true, message: '件数不能为空', trigger: 'blur' }],
				remark: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
				warehouseName: [{ required: true, message: '仓库不能为空', trigger: 'blur' }],
			},
			loading: false,
			city: '',
			updateSupplierData:[]
		}
	},
	components: {
		cityThree,
		selectOneSupplier,
		selectMoreGoods
	},
	created() { },
	mounted() {
		this.status = 1;
		this.getDetails();
	},
	methods: {
		// 获取子组件（选择商品）数据
		getMoreGoodsData(data){
			console.log(data,this.form.stockInItems)
			for(var i in data){
				data[i].goodsId = data[i].id;
				this.form.stockInItems.push(data[i]);
			}
		},
		// 获取子组件（选择供应商）数据
		getSupplierData(dataID, data) {
			console.log(dataID, data)
			this.supplierContact = data;
			this.supplierId = dataID;
			this.supplierMobile = data.supplierChannelNo;		//供应商手机
			this.supplierName = data.supplierName;
		},
		getDetails() {
			this.loading = true;
			this.$post("stockInDetails", {
				id: this.$route.params.id
			}).then(res => {
				this.form = res.data;
				var item = {
					id: this.form.supplierId,
					supplierName: this.form.supplierName,
					supplierMobile: this.form.supplierMobile,
					supplierContact: this.form.supplierContact,
				}
				this.updateSupplierData.push(item);
				console.log(this.updateSupplierData)
				this.loading = false;
			}).catch((e)=>{
				this.loading = false;
			})
		},
		// 添加进货单
		submitForm(formName) {
			this.loading = true;
			this.$refs[formName].validate((valid) => {
				if (valid) {
					var item = {
						id: this.$route.params.id,
						stockInItems: [this.form]
					}
					this.$post("stockInUpdate", item).then((res) => {
						this.loading = false;
						if (res.code == 200) {
							this.$msg.success("修改成功～");
							this.$router.back();
						} else {
							this.$msg.warning(res.message);
						}
					})
				} else {
					this.$msg.error("网络或服务器错误");
					this.loading = false;
				}
			});
		},
	}
};
</script>
<style lang="less" scoped>
.page {
  .content {
    width: 1000px;
    margin: 0 auto;
    .el-input {
      width: 600px;
    }
    .add-data {
      .el-input {
        width: 80%;
      }
    }
  }
}
</style>